package suanfa;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class groupAnagrams {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String,List<String>> hash=new HashMap<>();
        for(String str: strs){
            char[] tmp=str.toCharArray();
            Arrays.sort(tmp);
            String key=new String(tmp);
            if(!hash.containsKey(key)){
                hash.put(key,new ArrayList());
            }
            hash.get(key).add(str);
        }
        return new ArrayList(hash.values());
    }
}
